﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace comdiinfo
{
    public class G64TrackSpaceAfterGCRData : G64Element<byte[]>
    {
        public G64TrackSpaceAfterGCRData(int trackNo)
            : base(trackNo)
        {
            elementName = String.Format("Space after Data of Track {0}", CBMFunction.CBMTrackNoByTrackNo(trackNo));
        }
        public override void LoadData(ref G64ImageData imgData, int srcOffset, int count)
        {
            ElementValue = imgData.readBytes(srcOffset, count, elementName);
        }
        public override void CheckValue()
        {
            bool allEqual = true;
            byte firstByte = 0x55;
            if (ElementValue != null)
            {
                if (ElementValue.Length > 0)
                {
                    firstByte = ElementValue[0];
                    foreach (byte b in ElementValue)
                    {
                        if (firstByte != b)
                        {
                            allEqual = false;
                        }
                    }
                }
            }
            if ((allEqual) && (firstByte == 0x55))
            {
                elementStatus = G64ElementStatus.Ok;
            }
            else
            {
                elementStatus = G64ElementStatus.Warning;
                if (allEqual)
                {
                    elementStatusText.AppendFormat("{0} {1} ({2})", elementName, "sollte 0x55 sein!", firstByte.ToString("X2"));
                    elementStatusText.AppendLine();
                }
                else
                {
                    elementStatusText.AppendFormat("{0} {1}", elementName, "sollte immer 0x55 sein!");
                    elementStatusText.AppendLine();
                }
            }
        }
    }
}
